using System;
using Provausio.Common.Objects;
using TrainingManagement.api.Models.Data.CRUD;
using TrainingManagement.api.Models.Data.CRUD.Employee;

namespace TrainingManagement.api.Models.BusinessLogic.Employee
{
    public class EmployeeCreateOperation : BusinessOperation<BusinessObjects.Employee, BusinessObjects.Employee>
    {
        readonly EmployeeInsertDataSource _employeeInsert = new EmployeeInsertDataSource();

        public override BusinessObjects.Employee Run(BusinessObjects.Employee input)
        {
            var success = _employeeInsert.Execute(input);
            if (success) return input;
            
            throw new Exception("Employee was not saved.");
        }
    }
}